/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.*;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.punish.common.caseregister.service.IRegisterCommonService;
import com.icinfo.cloud.provider.punish.common.documentdataload.dto.CaseDataQueryDto;
import com.icinfo.cloud.provider.punish.common.documentdataload.dto.CaseDocumentRecordCommonQueryDto;
import com.icinfo.cloud.provider.punish.common.documentoperate.dto.DocumentRelateAttachmentVo;
import com.icinfo.cloud.provider.punish.common.documentoperate.dto.StageDocCommonOperateSaveDto;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentLinkObjectTypeEnum;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentRecordStatusEnum;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentStatusEnum;
import com.icinfo.cloud.provider.punish.common.documentoperate.service.IStageDocCommonOperateService;
import com.icinfo.cloud.provider.punish.common.electricsent.dto.DocumentSentRegisterInfoRequest;
import com.icinfo.cloud.provider.punish.common.electricsent.enums.SendWayEnum;
import com.icinfo.cloud.provider.punish.common.electricsent.service.IDocumentSentFlowService;
import com.icinfo.cloud.provider.punish.common.electricsent.vo.DocumentSentRegisterVo;
import com.icinfo.cloud.provider.punish.config.dto.ConfigDictionaryInfoQueryDto;
import com.icinfo.cloud.provider.punish.config.mapper.SysDepartParamMapper;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.model.SysDepartParam;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.config.service.IConfigDictionaryInfoService;
import com.icinfo.cloud.provider.punish.config.service.ISysDepartParamService;
import com.icinfo.cloud.provider.punish.config.vo.ConfigDictionaryInfoVo;
import com.icinfo.cloud.provider.punish.csource.manage.mapper.CaseSourceRegisterMainInfoMapper;
import com.icinfo.cloud.provider.punish.csource.manage.model.CaseSourceRegisterMainInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.*;
import com.icinfo.cloud.provider.punish.ucase.closearchiving.dto.CaseCloseArchivingDto;
import com.icinfo.cloud.provider.punish.ucase.closearchiving.vo.CaseCloseArchivingEchoVo;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.dto.CarryMaterial;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.dto.CaseAskNoticeDto;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.dto.CaseAskNoticePersonaDto;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.vo.AuthBookVo;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.vo.CasePartyNoticeVo;
import com.icinfo.cloud.workflow.config.mapper.ConfigWorkFlowDocumentMapper;
import com.icinfo.cloud.workflow.config.model.ConfigWorkFlowOperateDetailInfo;
import com.icinfo.cloud.workflow.config.service.IConfigWorkFlowOperateDetailInfoService;
import com.icinfo.cloud.workflow.work.model.WorkFlowRollRecordInfo;
import com.icinfo.cloud.workflow.work.service.IWorkFlowRollRecordInfoService;
import com.icinfo.cloud.xzcf.provider.member.role.api.UserRoleFeignApi;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.tools.utils.MapUtils;
import com.icinfo.framework.tools.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * 描述: 案件详情表（宽表）-TRJ case_main_detail_info 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年02月16日
 */
@Service
@Slf4j
@Transactional(rollbackFor = {Error.class, Exception.class})
public class CaseMainDetailInfoServiceImpl extends MyBatisServiceSupport implements ICaseMainDetailInfoService {
    @Resource
    private CaseMainDetailInfoMapper caseMainDetailInfoMapper;

    @Resource
    private ICaseRelatedDocumentRecordService caseRelatedDocumentRecordService;

    @Resource
    private ICaseAppendixRecordService caseAppendixRecordService;

    @Resource
    private CaseMainInfoMapper caseMainInfoMapper;

    @Resource
    private CasePartiesRecordMapper casePartiesRecordMapper;

    @Resource
    private CaseHandlePersonRecordMapper caseHandlePersonRecordMapper;

    @Resource
    private IStageDocCommonOperateService stageDocCommonOperateService;

    @Resource
    private CasePartiesPersonInfoMapper casePartiesPersonInfoMapper;

    @Resource
    private CasePartiesLegalInfoMapper casePartiesLegalInfoMapper;

    @Resource
    private CaseAppendixRecordMapper caseAppendixRecordMapper;
    @Resource
    private IRegisterCommonService commonService;
    @Resource
    private ICaseDocumentRecordService caseDocumentRecordService;
    @Resource
    private ICaseMainInfoService caseMainInfoService;
    @Resource
    private ICasePartiesRecordService casePartiesRecordService;
    @Autowired
    private IWorkFlowRollRecordInfoService workFlowRollRecordInfoService;
    @Autowired
    private IConfigWorkFlowOperateDetailInfoService configWorkFlowOperateDetailInfoService;
    @Resource
    private CaseMainDetailAuxiliaryInfoMapper caseMainDetailAuxiliaryInfoMapper;
    @Resource
    private SysDepartParamMapper sysDepartParamMapper;
    @Autowired
    private UserRoleFeignApi userRoleFeignApi;
    @Autowired
    private IConfigDictionaryInfoService configDictionaryInfoService;

    @Value("${dataReport.stageSwitch}")
    private String dataReportStageSwitch;
    @Resource
    private ISysDepartParamService sysDepartParamService;
    @Resource
    private ConfigWorkFlowDocumentMapper configWorkFlowDocumentMapper;
    @Resource
    private CaseSourceRegisterMainInfoMapper caseSourceRegisterMainInfoMapper;
    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;
    @Resource
    private IDocumentSentFlowService documentSentFlowService;

    private static Boolean carryMaterial(List<CarryMaterial> carryMaterialList) {
        SimpleDateFormat sd = new SimpleDateFormat("yyyy年MM月");
        Date date = new Date();
        Boolean flag = false;
        for (CarryMaterial carryMaterial : carryMaterialList) {
            String index = carryMaterial.getIndex();
            String value = carryMaterial.getValue();
            String state = carryMaterial.getState();
            if (Constant.STRING_TRUE.equals(state)) {
                if (Constant.STRING_2.equals(index)) {
                    try {
                        Date parse = sd.parse(value);
                        if (parse.getTime() <= date.getTime()) {
                            return flag;
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                if (Constant.STRING_4.equals(index) || Constant.STRING_5.equals(index) || Constant.STRING_6.equals(index)) {
                    if (timeValidation(value, sd, date)) {
                        return flag;
                    }
                }
            }
        }
        return flag;
    }

    private static Boolean timeValidation(String value, SimpleDateFormat sd, Date date) {
        Boolean flag = false;
        //String[] time = value.split(",");
        //前端传的时间格式是 2023年02月至2023年02月
        String[] time = value.split("至");
        try {
            Date start = sd.parse(time[0]);
            Date end = sd.parse(time[1]);
            if (start.getTime() >= end.getTime()) {
                flag = true;
            }
            if (end.getTime() >= date.getTime()) {
                flag = true;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return flag;
    }

    /**
     * 【V1.0.0】描述：保存案件主要详情信息
     *
     * @param saveDto {@link CaseMainDetailInfoSaveDto}
     * @return {@link Result<String>} 保存结果
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public Result<String> saveCaseMainDetailInfo(CaseMainDetailInfoSaveDto saveDto) {
        return null;
    }

    @Override
    public Map<String, Object> saveCloseInfo(CaseCloseArchivingDto caseCloseArchivingDto) {
        Example example = new Example(CaseMainDetailInfo.class);
        example.createCriteria().andEqualTo("caseId", caseCloseArchivingDto.getCaseId());
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByExample(example).get(0);
        // 20221206 结案日期取结案报告审批通过日期，注掉结案日期
//        LocalDate localDate = LocalDate.parse(caseCloseArchivingDto.getCloseDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//        caseMainDetailInfo.setCaseFinishDate(localDate);
        caseMainDetailInfo.setCaseFinishConditionIllustrate(caseCloseArchivingDto.getDesc());
        caseMainDetailInfo.setPersonReasonDetail(caseCloseArchivingDto.getPersonReasonDetail());
        caseMainDetailInfo.setIsRelateFarmer(caseCloseArchivingDto.getIsRelateFarmer());
        caseMainDetailInfo.setProjectType(caseCloseArchivingDto.getProjectType());
        int upr = caseMainDetailInfoMapper.updateByPrimaryKeySelective(caseMainDetailInfo);
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseCloseArchivingDto.getCaseId());
        caseMainInfo.setCaseFileNumber(caseCloseArchivingDto.getArchiveNo());
        caseMainInfo.setCaseLinkTag(caseCloseArchivingDto.getTag());
        //     caseMainInfo.setCaseEndTime(localDate.atTime(LocalTime.now()));
        if (TerritoryCodeEnum.RLSB.getCode().equals(caseMainInfo.getCaseTerritoryCode())) {
            CasePartiesLegalInfoIndustryTypeVo legalInfoIndustryTypeVo = caseCloseArchivingDto.getCasePartiesLegalInfoIndustryTypeVo();
            if (StringUtils.isNotBlank(legalInfoIndustryTypeVo.getId())) {
                CasePartiesLegalInfo updateCasePartiesLegalInfo = new CasePartiesLegalInfo();
                updateCasePartiesLegalInfo.setId(legalInfoIndustryTypeVo.getId());
                updateCasePartiesLegalInfo.setLegalIndustryType(legalInfoIndustryTypeVo.getLegalIndustryType());
                casePartiesLegalInfoMapper.updateByPrimaryKeySelective(updateCasePartiesLegalInfo);
            }

        }
        //修复清空附件不生效问题
        // 先删除
        Example example1 = new Example(CaseAppendixRecord.class);
        example1.createCriteria().andEqualTo("documentCatalogCode", caseCloseArchivingDto.getDocumentCatalogCode())
                .andEqualTo("caseStageCode", caseMainInfo.getCaseCurrentStageCode()).andEqualTo("caseId", caseMainDetailInfo.getCaseId());
        caseAppendixRecordMapper.deleteByExample(example1);
        // 附件保存调用李细军方法
        if (caseCloseArchivingDto.getAppendixList() != null && !caseCloseArchivingDto.getAppendixList().isEmpty()) {
            List<AppendixDto> list = caseCloseArchivingDto.getAppendixList();

            for (int i = 0; i < list.size(); i++) {
                CaseAppendixRecord record = new CaseAppendixRecord();
                record.setCaseId(caseMainDetailInfo.getCaseId());
                record.setCaseStageName(caseMainInfo.getCaseCurrentStageName());
                record.setCaseStageCode(caseMainInfo.getCaseCurrentStageCode());
                record.setCaseLinkName(caseMainInfo.getCaseCurrentLinkName());
                record.setCaseLinkCode(caseMainInfo.getCaseCurrentLinkCode());
                record.setDocumentCatalogCode(caseCloseArchivingDto.getDocumentCatalogCode());
                record.setAppendixUrl(list.get(i).getAppendixUrl());
                record.setAppendixTypeId(list.get(i).getAppendixTypeId());
                record.setAppendixName(list.get(i).getAppendixName());
                caseAppendixRecordService.saveCaseAppendixRecord(record);
            }
        }
        // 结案归档报告 下一步
        Boolean f = (upr == 1 && caseMainInfoMapper.updateByPrimaryKeySelective(caseMainInfo) == 1);
        if (f) {
            Map<String, Object> map = new HashMap<>(8);
            map.put("caseId", caseCloseArchivingDto.getCaseId());
            return map;
        } else {
            throw new BusinessException("保存结案信息时出现异常");
        }
    }

    @Override
    public CaseCloseArchivingEchoVo closeArchivingEcho(String caseId, String docId) {
        CaseCloseArchivingEchoVo vo = new CaseCloseArchivingEchoVo();
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseId);
        vo.setArchiveNo(caseMainInfo.getCaseFileNumber());
        vo.setTag(caseMainInfo.getCaseLinkTag());

        Example example = new Example(CaseMainDetailInfo.class);
        example.createCriteria().andEqualTo("caseId", caseId);
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByExample(example).get(0);
        vo.setCloseDate(caseMainDetailInfo.getCaseFinishDate() != null ? caseMainDetailInfo.getCaseFinishDate().toString() : "");
        vo.setDesc(caseMainDetailInfo.getCaseFinishConditionIllustrate());
        //如果人社条线，人社案由详情JSON字符串没有值，则给个初始值
        if (TerritoryCodeEnum.RLSB.getCode().equals(caseMainInfo.getCaseTerritoryCode()) && StrUtil.isEmpty(caseMainDetailInfo.getPersonReasonDetail()) && StrUtil.isNotEmpty(caseMainDetailInfo.getPersonReasonName())) {
            String[] personReasonNameArr = caseMainDetailInfo.getPersonReasonName().split(",");
            List<JSONObject> personReasonDetailList = CollUtil.newArrayList();
            for (String personReasonName : personReasonNameArr) {
                JSONObject personReasonDetail = new JSONObject();
                personReasonDetail.put("personReasonName", personReasonName);
                personReasonDetail.put("relateToAmount", "");
                personReasonDetail.put("relateToPersonNum", "");
                personReasonDetailList.add(personReasonDetail);
            }
            vo.setPersonReasonDetail(JSONObject.toJSONString(personReasonDetailList));
        } else {
            vo.setPersonReasonDetail(caseMainDetailInfo.getPersonReasonDetail());
        }
        //人力社保条线结案回显是否工程项目、是否涉及农民工、当事人所属行业
        if (TerritoryCodeEnum.RLSB.getCode().equals(caseMainInfo.getCaseTerritoryCode())) {
            vo.setIsRelateFarmer(caseMainDetailInfo.getIsRelateFarmer());
            vo.setProjectType(caseMainDetailInfo.getProjectType());
            if (StringUtils.isBlank(caseMainDetailInfo.getIsRelateFarmer()) && ApiVisitDataSourceEnum.PUNISH_AY.getCode().equals(caseMainInfo.getDataSource())) {
                CaseSourceRegisterMainInfo caseSourceRegisterMainInfo = caseSourceRegisterMainInfoMapper.selectByPrimaryKey(caseId);
                if (!ObjectUtils.isEmpty(caseSourceRegisterMainInfo)) {
                    vo.setIsRelateFarmer(caseSourceRegisterMainInfo.getIsRelateFarmer());
                    vo.setProjectType(caseSourceRegisterMainInfo.getProjectType());
                }
            }
            //获取法人当事人信息
            List<CasePartyRecordAdjustLegalSaveDto> casePartyRecordAdjustLegalSaveDtos = casePartiesLegalInfoMapper.selectCasePartiesLegalInfoDtoByCaseId(caseId);
            if (!ObjectUtils.isEmpty(casePartyRecordAdjustLegalSaveDtos)) {
                CasePartiesLegalInfoIndustryTypeVo legalInfoIndustryTypeVo = new CasePartiesLegalInfoIndustryTypeVo();
                legalInfoIndustryTypeVo.setId(casePartyRecordAdjustLegalSaveDtos.get(0).getId());
                legalInfoIndustryTypeVo.setLegalIndustryType(casePartyRecordAdjustLegalSaveDtos.get(0).getLegalIndustryType());
                vo.setCasePartiesLegalInfoIndustryTypeVo(legalInfoIndustryTypeVo);
            }
        }

        // 流程滚动后 附件无效
        Example example1 = new Example(CaseAppendixRecord.class);
        example1.createCriteria().andEqualTo("caseId", caseId).andEqualTo("caseStageCode", caseMainInfo.getCaseCurrentStageCode()).andEqualTo("documentCatalogCode", docId);
        List<CaseAppendixRecord> caseAppendixRecords = caseAppendixRecordMapper.selectByExample(example1);
        if (!caseAppendixRecords.isEmpty()) {
            List<AppendixDto> list = new ArrayList();
            for (CaseAppendixRecord rd : caseAppendixRecords) {
                AppendixDto dto = new AppendixDto();
                dto.setAppendixName(rd.getAppendixName());
                dto.setAppendixTypeId(rd.getAppendixTypeId());
                dto.setAppendixUrl(rd.getAppendixUrl());
                list.add(dto);
            }
            vo.setAppendixList(list);
        }
        return vo;
    }

    /**
     * 【V1.0.0】描述：获取案件主要详情列表
     *
     * @param queryDto {@link CaseMainDetailInfoQueryDto}
     * @return {@link Result<List<CaseMainDetailInfoVo>} 案件主要详情列表
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public List<CaseMainDetailInfoVo> getCaseMainDetailList(CaseMainDetailInfoQueryDto queryDto) {
        // FIXME: 2022/4/14 CFGZSTZL[听证类目前暂无]
        String kindCode = "CFGZSTZL";
        String sentDateTmp = queryDto.getSentDate();
        List<CaseMainDetailInfoVo> caseMainDetailInfoList = new ArrayList<>();
        CaseMainDetailInfoVo vo;
        if (YesOrNoEnum.YES.getCode().equals(queryDto.getIsInformDocSent())) {
            //事先告知信息上报条件（事先告知书送达后）需要单独查询送达记录表对应送达时间
            kindCode = "CFGZS";
        } else if (YesOrNoEnum.YES.getCode().equals(queryDto.getIsPunishDecideDocSent())) {
            //决定信息上报条件（处罚决定书送达后）需要单独查询送达记录表对应送达时间
            kindCode = Constant.STRING_KIND_CODE_CFJDS;
        } else if (YesOrNoEnum.YES.getCode().equals(queryDto.getIsInvestigateOverReportDocGenerated())) {
            //调查信息上报条件（案件调查终结报告生成后）案件调查终结报告生成时间
            kindCode = "ZJBG";
        }
        if (YesOrNoEnum.YES.getCode().equals(queryDto.getIsInformDocSent()) || YesOrNoEnum.YES.getCode().equals(queryDto.getIsPunishDecideDocSent())) {
            List<CaseDocumentRecordVo> caseDocumentRecordList = caseDocumentRecordService.getCaseDocumentRecordListWithKindCode(kindCode, sentDateTmp, null);
            for (CaseDocumentRecordVo e : caseDocumentRecordList) {
                if (!ObjectUtils.isEmpty(e)) {
                    vo = new CaseMainDetailInfoVo();
                    vo.setCaseId(e.getCaseId());
                    caseMainDetailInfoList.add(vo);
                }
            }
            return caseMainDetailInfoList;
        } else if (YesOrNoEnum.YES.getCode().equals(queryDto.getIsInvestigateOverReportDocGenerated())) {
            //单独查询调查终结报告的生成时间
            List<CaseDocumentRecordVo> caseDocumentRecordList = caseDocumentRecordService.getCaseDocumentRecordListWithKindCode(kindCode, null, sentDateTmp);
            for (CaseDocumentRecordVo e : caseDocumentRecordList) {
                if (!ObjectUtils.isEmpty(e)) {
                    vo = new CaseMainDetailInfoVo();
                    vo.setCaseId(e.getCaseId());
                    caseMainDetailInfoList.add(vo);
                }
            }
            return caseMainDetailInfoList;
        }
        return caseMainDetailInfoMapper.selectCaseMainDetailList(queryDto);
    }

    /**
     * 【V1.1.0】描述：获取案件id列表-需要上报的立案信息
     *
     * @return {@link List<String>} 案件id列表
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public List<String> getCaseIdListShouldReportBasicInfo() {
        if (Constant.STRING_DATA_REPORT_STAGE_SWITCH_OPEN.equals(dataReportStageSwitch)) {
            return caseMainDetailInfoMapper.selectCaseIdListShouldReportBasicInfo();
        }
        return caseMainDetailInfoMapper.selectCaseIdListShouldReportBasicInfoRefactor();
    }

    /**
     * 【V1.2.0】描述：获取案件id列表-需要上报的立案信息
     *
     * @param punishDecideCaseIdList 处罚决定的案件ID列表
     * @return {@link Result <String>} 案件id列表
     * @author mahan
     * @date 2022-10-20 18:52
     */
    @Override
    public List<String> getCaseIdListShouldReportBasicInfo(List<String> punishDecideCaseIdList) {
        return caseMainDetailInfoMapper.selectReportBasicInfoCaseIdList(punishDecideCaseIdList);
    }

    /**
     * 【V1.1.0】描述：获取立案信息上报成功的所有案件id
     *
     * @return {@link List<String>} 案件id列表
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public List<String> getReReportBaseCaseIdList() {
        return caseMainDetailInfoMapper.selectReReportBaseCaseIdList();
    }

    /**
     * 【V1.1.0】描述：获取决定信息上报成功的所有案件id
     *
     * @return {@link List<String>} 案件id列表
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public List<String> getReReportDecisionCaseIdList() {
        return caseMainDetailInfoMapper.selectReReportDecisionCaseIdList();
    }

    /**
     * 【V1.1.0】描述：获取案件id列表-需要上报的执行信息
     *
     * @return {@link List<String>} 案件id列表
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public List<String> getCaseIdListShouldReportExecuteInfo() {
        if (Constant.STRING_DATA_REPORT_STAGE_SWITCH_OPEN.equals(dataReportStageSwitch)) {
            return caseMainDetailInfoMapper.selectCaseIdListShouldReportExecuteInfo();
        }
        return caseMainDetailInfoMapper.selectCaseIdListShouldReportExecuteInfoRefactor();
    }

    /**
     * 【V1.1.0】描述：获取案件id列表-需要上报的结案信息
     *
     * @return {@link List<String>} 案件id列表
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public List<String> getCaseIdListShouldReportCaseOverInfo() {
        if (Constant.STRING_DATA_REPORT_STAGE_SWITCH_OPEN.equals(dataReportStageSwitch)) {
            return caseMainDetailInfoMapper.selectCaseIdListShouldReportCaseOverInfo();
        }
        return caseMainDetailInfoMapper.selectCaseIdListShouldReportCaseOverInfoRefactor();
    }

    /**
     * 【V1.0.0】描述：根据唯一标识查询案件主要详情信息
     *
     * @param id 唯一标识
     * @return {@link CaseMainDetailInfoVo} 案件主要详情信息
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public CaseMainDetailInfoVo getCaseMainDetailInfo(String id) {
        return null;
    }

    /**
     * 【V1.0.0】描述：删除案件主要详情信息
     *
     * @param id 主键id
     * @return {@link Result<String>} 删除结果
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @Override
    public Result<String> removeCaseMainDetail(String id) {
        return null;
    }

    /**
     * 根据案件id获取案件详情数据
     *
     * @param caseId
     * @return {@link CaseMainDetailInfo}
     * @author liyafeng
     * @date 2022/2/25
     */
    @Override
    public CaseMainDetailInfo getCaseMainDetailByCaseId(String caseId) {
        Example example = new Example(CaseMainDetailInfo.class);
        example.createCriteria().andEqualTo("caseId", caseId);
        List<CaseMainDetailInfo> caseMainDetailInfos = caseMainDetailInfoMapper.selectByExample(example);
        if (null != caseMainDetailInfos && caseMainDetailInfos.size() > 0) {
            CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfos.get(0);
            return caseMainDetailInfo;
        } else {
            throw new BusinessException("未获取到案件详情信息-caseId:" + caseId);
        }
    }

    /**
     * 询问通知书页面信息接口
     *
     * @param caseId
     * @param partyId
     * @return CasePartyNoticeVo
     * @author lxj
     * @date 2022/3/2
     **/
    @Override
    public CasePartyNoticeVo getNoticeMsg(String caseId, String partyId) {

        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        if (caseMainDetailInfo == null) {
            return null;
        }
        CasePartyNoticeVo vo = new CasePartyNoticeVo();
        vo.setCaseAddress(caseMainDetailInfo.getCaseHappenAddressDetail());
        vo.setCaseOrgAddress(caseMainDetailInfo.getCaseOrgAddress());

        vo.setCaseReason(BaseUtil.handleCaseReason(caseMainDetailInfo.getCaseReason()));
        vo.setCaseHappenTime(caseMainDetailInfo.getCaseHappenTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
        //查询当事人信息
        CasePartiesRecordVo record = null;
        List<CasePartiesRecordVo> casePartiesRecordList = casePartiesRecordService.getCasePartiesInfo(caseId);
        if (!ObjectUtils.isEmpty(partyId)) {
            for (CasePartiesRecordVo partiesRecord : casePartiesRecordList) {
                if (partyId.equals(partiesRecord.getPartyId())) {
                    record = partiesRecord;
                    break;
                }
            }
        } else {
            record = casePartiesRecordList.get(Constant.INTEGER_0);
        }
        if (!ObjectUtils.isEmpty(record)) {
            vo.setPartyName(record.getPartyName());
        }
        //查询办案人员--主办，协办
        Example exampleHandle = new Example(CaseHandlePersonRecord.class);
        exampleHandle.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
        List<CaseHandlePersonRecord> list = caseHandlePersonRecordMapper.selectByExample(exampleHandle);
        list.forEach(caseHandlePersonRecord -> {
            if (Constant.STRING_1.equals(caseHandlePersonRecord.getHandlePersonType())) {
                vo.setMainHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                vo.setMainLawEnforcementCert(caseHandlePersonRecord.getLawEnforcementCert());
                vo.setOrgPhone(caseHandlePersonRecord.getHandleOrgTel());
                vo.setDeptPhone(caseHandlePersonRecord.getHandleDeptTel());
                vo.setMainSign(caseHandlePersonRecord.getHandleSignPic());
                vo.setHandleOrgName(caseHandlePersonRecord.getHandleOrgName());
                String handleOrgCode = caseHandlePersonRecord.getHandleOrgCode();
                String handleDeptCode = caseHandlePersonRecord.getHandleDeptCode();
                if (StringUtils.isNotBlank(handleOrgCode)) {
                    /*List<SysDepartParam> sysDepartParams=new ArrayList<>();
                    SysDepartParam sysDepartParam=new SysDepartParam();
                    String isConfigDept=Constant.STRING_0;
                    Example example = new Example(SysDepartParam.class);
                    example.createCriteria().andEqualTo("orgCode",handleOrgCode).andIsNull("deptCode").andEqualTo("isDeleted",Constant.STRING_0);
                    sysDepartParams = sysDepartParamMapper.selectByExample(example);
                    if (!ObjectUtils.isEmpty(sysDepartParams)){
                        sysDepartParam = sysDepartParams.get(Constant.INTEGER_0);
                        isConfigDept=sysDepartParams.get(0).getIsConfigDept();
                    }
                    if(Constant.STRING_1.equals(isConfigDept)){
                        Example deptExample = new Example(SysDepartParam.class);
                        deptExample.createCriteria().andEqualTo("orgCode", handleOrgCode).andEqualTo("deptCode",handleDeptCode).andEqualTo("isDeleted",Constant.STRING_0);
                        sysDepartParams = sysDepartParamMapper.selectByExample(example);
                        if(!ObjectUtils.isEmpty(sysDepartParams)){
                            sysDepartParam=sysDepartParams.get(0);
                        }
                    }*/
                    SysDepartParam sysDepartParam = sysDepartParamService.getSysDepartParamByOrgCodeAndDeptCode(handleOrgCode, handleDeptCode);
                    vo.setAddress(sysDepartParam.getAddress());
                    // 部门联系电话
                    vo.setCompanyTel(sysDepartParam.getPhone());
                }
                //生态条线法制人员存在
            } else if (Constant.STRING_3.equals(caseHandlePersonRecord.getHandlePersonType())) {
                vo.setLegalLawEnforcementCert(caseHandlePersonRecord.getLawEnforcementCert());
                vo.setLegalHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                vo.setLegalHandlePersonTel(caseHandlePersonRecord.getHandlePersonTel());
            } else {
                vo.setHelpLawEnforcementCert(caseHandlePersonRecord.getLawEnforcementCert());
                vo.setHelpHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                vo.setAssiSign(caseHandlePersonRecord.getHandleSignPic());
            }
        });
        return vo;
    }

    /**
     * 保存询问通知书
     *
     * @param caseAskNoticeDto
     * @return boolean
     * @author lxj
     * @date 2022/3/3
     **/
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Map<String, Object> saveAskNoticeBook(CaseAskNoticeDto caseAskNoticeDto) {
        //更新
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseAskNoticeDto.getCaseId());
        if (caseMainInfo == null) {
            return null;
        }
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseAskNoticeDto.getCaseId());
        caseMainDetailInfo.setAcceptInquireAddress(caseAskNoticeDto.getAcceptInquireAddress());
        caseMainDetailInfo.setAcceptInquireCarryMaterial(caseAskNoticeDto.getAcceptInquireCarryMaterial());
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        caseMainDetailInfo.setAcceptInquireTime(LocalDateTime.parse(caseAskNoticeDto.getAcceptInquireTime() + ":00", df));
        caseMainDetailInfo.setInquireDocGenerateTime(LocalDateTime.now());
        caseMainDetailInfoMapper.updateByPrimaryKeySelective(caseMainDetailInfo);
        //增加送达当事人id处理
        if (ObjectUtils.isEmpty(caseAskNoticeDto.getPartyId())) {
            String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();
            if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)) {
                throw new BusinessException("多当事人案件需指定当事人id");
            }
            Map<String, String> map = casePartiesRecordService.getCasePartyIdNameInfo(caseAskNoticeDto.getCaseId());
            String partyId = map.get("partyId");
            caseAskNoticeDto.setPartyId(partyId);
        }

        //3.调用文书生成公用方法-
        StageDocCommonOperateSaveDto saveDto = new StageDocCommonOperateSaveDto();
        saveDto.setCaseId(caseAskNoticeDto.getCaseId());
        saveDto.setDocumentCatalogCode(caseAskNoticeDto.getDocumentCatalogCode());
        caseAskNoticeDto.setOrgName(caseMainInfo.getCaseOrgName());
        caseAskNoticeDto.setAuthedCreateDate(BaseUtil.getNowDate());

        caseAskNoticeDto.setAskTime(BaseUtil.getFormatDateTime(caseAskNoticeDto.getAcceptInquireTime()));
        caseAskNoticeDto.setCaseReason(BaseUtil.handleCaseReason(caseAskNoticeDto.getCaseReason()));
        UserDTO userDTO = UserUtil.getUserInfo();
        caseAskNoticeDto.setOrgStandardName(commonService.getOrgStandardNameByOrgCode(userDTO.getOrgCode(), userDTO.getDeptCode()));
        saveDto.setDataMap(BaseUtil.javaToMap(caseAskNoticeDto));
        saveDto.setIsUpdateRelationTable(Constant.STRING_0);
        //设置当事人id
        saveDto.setPartyId(caseAskNoticeDto.getPartyId());
        Map<String, Object> retMap = stageDocCommonOperateService.saveDocInfo(saveDto);
        String status = MapUtils.getString(retMap, "success", "");
        if (!"true".equals(status)) {
            log.info("--saveAskNoticeBook请求接口-saveDocInfo返回值-" + retMap);
            throw new RuntimeException();
        }
        return retMap;
    }

    /**
     * 获取授权委托书页面固定信息
     *
     * @param caseId 入参
     * @return AuthBookVo
     * @author lxj
     * @date 2022/2/16
     **/
    @Override
    public AuthBookVo getCaseEntrustBookNeedMsg(String caseId, String partyId) {
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        if (caseMainDetailInfo == null) {
            return null;
        }

        //增加送达当事人id处理
        if (ObjectUtils.isEmpty(partyId)) {
            CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
            String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();
            if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)) {
                throw new BusinessException("多当事人案件需指定当事人id");
            }
            Map<String, String> map = casePartiesRecordService.getCasePartyIdNameInfo(caseId);
            partyId = map.get("partyId");
        }

        AuthBookVo vo = new AuthBookVo();
        vo.setCaseHappenAddress(caseMainDetailInfo.getCaseHappenAddressDetail());
        vo.setCaseReason(caseMainDetailInfo.getCaseReason());

        CasePartiesRecordVo record = casePartiesRecordService.getCasePartiesInfoByPartyId(caseId, partyId);
        vo.setPartyName(record.getPartyName());
        vo.setPartyType(record.getPartyType());
        //查询办案人员--主办，协办
        Example exampleHandle = new Example(CaseHandlePersonRecord.class);
        exampleHandle.createCriteria().andEqualTo("caseId", caseId);
        if (PartyTypeEnum.PERSON.getCode().equals(record.getPartyType())) {
            CasePartiesPersonInfo casePartiesPersonInfo = casePartiesPersonInfoMapper.selectByPrimaryKey(record.getPartyId());
            vo.setAddress(casePartiesPersonInfo.getAddress());
            vo.setEntrustJob(casePartiesPersonInfo.getJob());
            vo.setPhone(casePartiesPersonInfo.getMobile());
            vo.setCertType(casePartiesPersonInfo.getCertType());
            vo.setCertTypeName(CertTypeEnum.getValueByCode(casePartiesPersonInfo.getCertType()));
            vo.setCertNo(casePartiesPersonInfo.getCertNo());
        } else if (PartyTypeEnum.LEGAL.getCode().equals(record.getPartyType())) {
            CasePartiesLegalInfo casePartiesLegalInfo = casePartiesLegalInfoMapper.selectByPrimaryKey(record.getPartyId());
            vo.setAddress(casePartiesLegalInfo.getAddress());
            vo.setEntrustJob(casePartiesLegalInfo.getJob());
            vo.setPhone(casePartiesLegalInfo.getPhone());
            vo.setEntrustLegalName(casePartiesLegalInfo.getLegalName());
            vo.setCertType(casePartiesLegalInfo.getLegalCertType());
            vo.setCertNo(casePartiesLegalInfo.getLegalCertNo());
            vo.setCertTypeName(CertTypeEnum.getValueByCode(casePartiesLegalInfo.getLegalCertType()));
            vo.setEntType(casePartiesLegalInfo.getEntType());
        }
        return vo;
    }

    /**
     * 根据案件id获取可撤回的列表
     *
     * @param caseId 入参
     * @return CaseRecallLinkVo
     * @author tianrunjia
     * @date 2022/6/24
     **/
    @Override
    public List<CaseRecallLinkVo> getCaseRecallLinkListById(String caseId) {
        List<WorkFlowRollRecordInfo> workFlowRollRecordInfoList = workFlowRollRecordInfoService.getWorkRollRecordHandleByWorkId(caseId);
        CaseMainInfoVo caseMainInfoVo = caseMainInfoMapper.selectCaseMainInfo(caseId);
        Boolean isNotAllPunish = false;
        //多当事人分别处罚
        if (Constant.STRING_2.equals(caseMainInfoVo.getHandleType())) {
            Example example = new Example(CaseMainDetailAuxiliaryInfo.class);
            example.createCriteria().andEqualTo("caseId", caseId);
            List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfos = caseMainDetailAuxiliaryInfoMapper.selectByExample(example);
            Set<String> set = new LinkedHashSet<>();
            for (CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo : caseMainDetailAuxiliaryInfos) {
                if (StringUtils.isNotBlank(caseMainDetailAuxiliaryInfo.getInvestConclusion())) {
                    set.add(caseMainDetailAuxiliaryInfo.getInvestConclusion());
                }
            }
            if (set.size() > 1) {
                isNotAllPunish = true;
            }
        }
        List<CaseRecallLinkVo> caseRecallLinkVoList = new ArrayList<>();
        if (isNotAllPunish) {
            workFlowRollRecordInfoList.forEach(e -> {
                if (!"立案".equals(e.getWorkStageName()) && !"处罚告知".equals(e.getWorkStageName()) && !"处罚决定".equals(e.getWorkStageName())) {
                    CaseRecallLinkVo recallLinkVo = new CaseRecallLinkVo();
                    recallLinkVo.setCaseLinkCode(e.getWorkLinkCode());
                    recallLinkVo.setCaseLinkName(e.getWorkLinkName());
                    caseRecallLinkVoList.add(recallLinkVo);
                }
            });
        } else {
            workFlowRollRecordInfoList.forEach(e -> {
                //TODO 撤回不允许撤回到陈述申辩，暂时这样写，后续优化
                if (!"立案".equals(e.getWorkStageName()) && !"陈述申辩/放弃陈述申辩".equals(e.getWorkLinkName())) {
                    CaseRecallLinkVo recallLinkVo = new CaseRecallLinkVo();
                    recallLinkVo.setCaseLinkCode(e.getWorkLinkCode());
                    recallLinkVo.setCaseLinkName(e.getWorkLinkName());
                    caseRecallLinkVoList.add(recallLinkVo);
                }
            });
        }
        return caseRecallLinkVoList;
    }

    @Override
    public CaseMainDetailInfoCommonVo getCaseMainDetailInfoCommonVoByCaseId(CaseDataQueryDto queryDto) {
        String caseId = queryDto.getCaseId();
        String partyId = queryDto.getPartyId();
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseId);
        String deptCode = caseMainInfo.getCaseDeptCode();
        Example example = new Example(SysDepartParam.class);
        example.createCriteria().andEqualTo("orgCode", caseMainInfo.getCaseOrgCode()).andEqualTo("deptCode", caseMainInfo.getCaseDeptCode()).andEqualTo("isDeleted", Constant.STRING_0);
        List<SysDepartParam> sysDepartParamList = sysDepartParamMapper.selectByExample(example);
        if (ObjectUtils.isEmpty(sysDepartParamList)) {
            deptCode = "";
        }
        CaseMainDetailInfoCommonVo commonVo = caseMainDetailInfoMapper.selectCaseMainDetailInfoCommonVoByCaseId(caseId, deptCode);
        if (CaseStageEnum.PUNISH_EXECUTION.getCode().equals(commonVo.getCaseCurrentStageCode())
                || CaseStageEnum.CLOSE_ARCHIVING.getCode().equals(commonVo.getCaseCurrentStageCode())) {
            CaseDocumentRecordCommonQueryDto commonQueryDto = new CaseDocumentRecordCommonQueryDto();
            commonQueryDto.setCaseId(caseId);
            commonQueryDto.setPartyId(partyId);
            commonQueryDto.setIsPunishDocument(Constant.STRING_1);
            List<CaseDocumentRecordDetailVo> caseDocumentRecordDetailVoList = caseDocumentRecordService.getCaseDocumentRecordDocNumberInfoList(commonQueryDto);
            for (CaseDocumentRecordDetailVo detailVo : caseDocumentRecordDetailVoList) {
                detailVo.setSentWay(SendWayEnum.getValueByCode(detailVo.getSentWay()));
            }
            commonVo.setPunishDocumentVoList(caseDocumentRecordDetailVoList);
        }
        String handleType = commonVo.getHandleType();
        String casePartiesReasonType = commonVo.getCasePartiesReasonType();
        // 多当事人分别处罚
        if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                && HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)) {
            //根据当事人id、案件id查询 案件详情补充表
            Example auxiliaryExample = new Example(CaseMainDetailAuxiliaryInfo.class);
            auxiliaryExample.createCriteria().andEqualTo("caseId", caseId).andEqualTo("partyId", partyId);
            List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfos = caseMainDetailAuxiliaryInfoMapper.selectByExample(auxiliaryExample);
            if (!ObjectUtils.isEmpty(caseMainDetailAuxiliaryInfos) && caseMainDetailAuxiliaryInfos.size() > 0) {
                CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryInfos.get(0);
                commonVo.setPunishKinds(caseMainDetailAuxiliaryInfo.getPunishKinds());
                commonVo.setInvestConclusion(caseMainDetailAuxiliaryInfo.getInvestConclusion());
            }
        }
        return commonVo;
    }

    @Override
    public Map<String, Object> saveAskNoticeBookPersona(CaseAskNoticePersonaDto caseAskNoticePersonaDto) {
        //更新
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseAskNoticePersonaDto.getCaseId());
        if (caseMainInfo == null) {
            return null;
        }
        //人设的询问通知书
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseAskNoticePersonaDto.getCaseId());
        caseMainDetailInfo.setAcceptInquireAddress(caseAskNoticePersonaDto.getAcceptInquireAddress());
        // 询问地址
        caseMainDetailInfo.setAcceptInquireAddressPerson(caseAskNoticePersonaDto.getAcceptInquireAddressPerson());
        // 询问情况
        caseMainDetailInfo.setAcceptInquireSituation(caseAskNoticePersonaDto.getAcceptInquireSituation());
        // 携带资料时间验证
        if (carryMaterial(caseAskNoticePersonaDto.getAcceptInquireCarryMaterial())) {
            throw new BusinessException("携带资料时间验证不通过，请检查时间区间。");
        }
        caseMainDetailInfo.setAcceptInquireCarryMaterial(JSON.toJSONString(caseAskNoticePersonaDto.getAcceptInquireCarryMaterial()));
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        caseMainDetailInfo.setAcceptInquireTime(LocalDateTime.parse(caseAskNoticePersonaDto.getAcceptInquireTime() + ":00", df));
        caseMainDetailInfo.setInquireDocGenerateTime(LocalDateTime.now());
        caseMainDetailInfoMapper.updateByPrimaryKeySelective(caseMainDetailInfo);
        //增加送达当事人id处理
        if (ObjectUtils.isEmpty(caseAskNoticePersonaDto.getPartyId())) {
            String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();
            if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)) {
                throw new BusinessException("多当事人案件需指定当事人id");
            }
            Map<String, String> map = casePartiesRecordService.getCasePartyIdNameInfo(caseAskNoticePersonaDto.getCaseId());
            String partyId = map.get("partyId");
            caseAskNoticePersonaDto.setPartyId(partyId);
        }

        //3.调用文书生成公用方法-
        StageDocCommonOperateSaveDto saveDto = new StageDocCommonOperateSaveDto();
        saveDto.setCaseId(caseAskNoticePersonaDto.getCaseId());
        saveDto.setDocumentCatalogCode(caseAskNoticePersonaDto.getDocumentCatalogCode());
        caseAskNoticePersonaDto.setOrgName(caseMainInfo.getCaseOrgName());
        caseAskNoticePersonaDto.setAuthedCreateDate(BaseUtil.getNowDate());

        caseAskNoticePersonaDto.setAskTime(BaseUtil.getFormatDateTime(caseAskNoticePersonaDto.getAcceptInquireTime()));
        //caseAskNoticePersonaDto.setCaseReason(BaseUtil.handleCaseReason(caseAskNoticePersonaDto.getCaseReason()));
        UserDTO userDTO = UserUtil.getUserInfo();
        caseAskNoticePersonaDto.setOrgStandardName(commonService.getOrgStandardNameByOrgCode(userDTO.getOrgCode(), userDTO.getDeptCode()));
        for (int i = 0; i < caseAskNoticePersonaDto.getAcceptInquireCarryMaterial().size(); i++) {
            CarryMaterial carryMaterial = caseAskNoticePersonaDto.getAcceptInquireCarryMaterial().get(i);
            if (i != Constant.INTEGER_2 || i != Constant.INTEGER_6) {
                carryMaterial.setValue(carryMaterial.getValue().replace(",", "至"));
            }
        }
        HashMap hashMap = BaseUtil.javaToMap(caseAskNoticePersonaDto);
        // 处理pdf文书渲染选择接受询问
        //处理
        saveDto.setDataMap(hashMap);
        saveDto.setIsUpdateRelationTable(Constant.STRING_0);
        //设置当事人id
        saveDto.setPartyId(caseAskNoticePersonaDto.getPartyId());
        Map<String, Object> retMap = stageDocCommonOperateService.saveDocInfo(saveDto);
        String status = MapUtils.getString(retMap, "success", "");
        if (!"true".equals(status)) {
            log.info("--saveAskNoticeBookPersona请求接口-saveDocInfo返回值-" + retMap);
            throw new RuntimeException();
        }
        return retMap;
    }

    /**
     * 【V1.10.0】描述：获取文书按阶段的列表及每个文书的状态及对应的操作
     *
     * @param caseId 案件id
     * @author tianrunjia
     * @date 2022-12-11
     */
    @Override
    public List<CaseStageDocumentRelationInfoVo> getCaseStageDocumentDetailInfos(String caseId) {
        /*List<CaseDocumentCatalogChainInfoVo> caseSourceDocumentCatalogChainInfoVos = new ArrayList<>();
        List<CaseDocumentCatalogChainInfoVo> caseDocumentCatalogChainInfoVos = new ArrayList<>();*/

        //汇总列表
        List<CaseStageDocumentRelationInfoVo> caseStageDocumentRelationInfoVoList = new ArrayList<>();

        //案件基础信息
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        if (ObjectUtils.isEmpty(caseMainInfo) || CaseStatusEnum.TEMP.getCode().equals(caseMainInfo.getCaseStatus())) {
            return caseStageDocumentRelationInfoVoList;
        }
        //案件案由、当事人类型
        String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();

        //案件阶段查询
        //案源
        if (ApiVisitDataSourceEnum.PUNISH_AY.getCode().equals(caseMainInfo.getDataSource())) {
            CaseStageDocumentRelationInfoVo catalogRelationVo = new CaseStageDocumentRelationInfoVo();
            catalogRelationVo.setCaseStageCode(Constant.CASE_SOURCE_STAGE_YLA);
            catalogRelationVo.setCaseStageName(Constant.CASE_SOURCE_STAGE_CODE);
            caseStageDocumentRelationInfoVoList.add(catalogRelationVo);
        }
        //其他
        ConfigDictionaryInfoQueryDto dto = new ConfigDictionaryInfoQueryDto();
        dto.setIsEffective(Constant.STRING_1);
        dto.setDicFieldCode(Constant.STRING_CASE_STAGE);
        List<ConfigDictionaryInfoVo> configDictionaryInfoVos = configDictionaryInfoService.getConfigDictionaryList(dto);
        configDictionaryInfoVos.forEach(e -> {
            CaseStageDocumentRelationInfoVo catalogRelationVo = new CaseStageDocumentRelationInfoVo();
            catalogRelationVo.setCaseStageCode(e.getDicCode());
            catalogRelationVo.setCaseStageName(e.getDicName());
            caseStageDocumentRelationInfoVoList.add(catalogRelationVo);
        });


        //文书
        List<CaseDocumentRecordInfo> caseDocumentRecordInfoList = caseDocumentRecordService.doCaseDetailStageDocumentRecordByCaseId(caseId, caseMainInfo.getBusiParamId());
        //附件
        List<CaseAttachmentInfoVo> attachmentsList = new ArrayList<>();
        //当事人
        List<CasePartiesRecordVo> casePartiesRecordList = new ArrayList<>();
        if (caseDocumentRecordInfoList.size() > 0) {
            CaseAttachmentInfoQueryDto queryDto = new CaseAttachmentInfoQueryDto();
            queryDto.setCaseId(caseId);
            attachmentsList = caseAppendixRecordService.getCaseAttachmentList(queryDto);
            casePartiesRecordList = casePartiesRecordService.getCasePartiesInfo(caseId);
        }


        List<CaseStageDocumentDetailInfoVo> caseStageDocumentDetailInfoVoList = new ArrayList<>();
        //查询配对文书编码
        List<String> isMatchDocumentList = configWorkFlowDocumentMapper.selectIsMatchDocumentCodeList(caseMainInfo.getCaseFlowCode(), caseMainInfo.getCaseFlowVersion());
        for (CaseDocumentRecordInfo e : caseDocumentRecordInfoList) {
            if (!DocumentRecordStatusEnum.WITHDRAW.getCode().equals(e.getDocumentRecordStatus())) {
                CaseStageDocumentDetailInfoVo caseStageDocumentDetailInfoVo = new CaseStageDocumentDetailInfoVo();
                BeanUtils.copyProperties(e, caseStageDocumentDetailInfoVo);

                //文书地址逻辑
                if (org.apache.commons.lang3.StringUtils.isNotBlank(e.getDocumentAftersealUrl())) {
                    caseStageDocumentDetailInfoVo.setDocumentUrl(e.getDocumentAftersealUrl());
                }
                if (org.apache.commons.lang3.StringUtils.isNotBlank(e.getDocumentAfterSignUrl())) {
                    caseStageDocumentDetailInfoVo.setDocumentUrl(e.getDocumentAfterSignUrl());
                }

                //文书名称
                if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                        && DocumentLinkObjectTypeEnum.PERSON.getCode().equals(e.getDocumentLinkObjectType())
                        && (!ObjectUtils.isEmpty(e.getPartyId()) && !e.getPartyId().contains(",")) && casePartiesRecordList.size() > 0) {
                    //多当事人合并处罚不拼接当事人名称
                    //查询当事人名称
                    String partyName = "";
                    for (CasePartiesRecordVo ele : casePartiesRecordList) {
                        String tmpPartyId = ele.getPartyId();
                        if (e.getPartyId().equals(tmpPartyId)) {
                            partyName = ele.getPartyName();
                            break;
                        }
                    }
                    caseStageDocumentDetailInfoVo.setDocumentKindName(e.getDocumentKindName() + "(" + partyName + ")");
                }
                //附件
                if (attachmentsList.size() > 0) {
                    List<DocumentRelateAttachmentVo> documentRelateAttachmentList = new ArrayList<>();
                    attachmentsList.forEach(f -> {
                        if (e.getDocumentCatalogCode().equals(f.getDocumentCatalogCode())) {
                            DocumentRelateAttachmentVo documentRelateAttachmentVo = new DocumentRelateAttachmentVo();
                            documentRelateAttachmentVo.setAttachmentId(f.getId());
                            documentRelateAttachmentVo.setAttachmentTitle(f.getAppendixName());
                            documentRelateAttachmentVo.setAttachmentUrl(f.getAppendixUrl());
                            documentRelateAttachmentVo.setAttachmentType(f.getAppendixType());
                            documentRelateAttachmentList.add(documentRelateAttachmentVo);
                        }
                    });
                    caseStageDocumentDetailInfoVo.setDocumentRelateAttachmentList(documentRelateAttachmentList);
                }
                //单当事人通过此方法获取送达登记（移动端需要获取）
                if (!PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)) {
                    //获取送达登记
                    DocumentSentRegisterInfoRequest request = new DocumentSentRegisterInfoRequest();
                    request.setCaseId(caseMainInfo.getId());
                    request.setDocumentId(e.getDocumentId());
                    request.setPartyId(casePartiesRecordList.get(0).getPartyId());
                    request.setDataSource(ApiVisitDataSourceEnum.PUNISH_MOBILE.getId());
                    DocumentSentRegisterVo vo = documentSentFlowService.getDocumentSentRegisterInfo(request);
                    if (!Objects.isNull(vo) && !StrUtil.isBlank(vo.getId())) {
                        caseStageDocumentDetailInfoVo.setDocumentSentRegisterVoList(Collections.singletonList(vo));
                    }
                }

                //文书状态及对应操作处理
                boolean isMatchDocument = false;
                if (isMatchDocumentList.contains(e.getDocumentCatalogCode())) {
                    isMatchDocument = true;
                }
                initDocumentOperateInfo(caseStageDocumentDetailInfoVo, e, isMatchDocument);
                //速结程序立案审批表操作按钮特殊处理
                if (CaseTypeEnum.SIMPLE_QUICK.getCode().equals(caseMainInfo.getCaseType())
                        && DocumentKindEnum.DOC_KIND_LASPB.getCode().equals(e.getDocumentKindCode())) {
                    //速结告知书已确认立案审批表不允许修改
                    dealLASPBDocumentOperateInfo(caseStageDocumentDetailInfoVo, caseId);
                }

                caseStageDocumentDetailInfoVoList.add(caseStageDocumentDetailInfoVo);
            }
        }
        //关联文书
        List<CaseStageLinkRelateDocumentVo> relatedDocList = caseRelatedDocumentRecordService.getRelatedDocInfoToCaseStageLinkRelateDocument(caseId);
        caseStageDocumentRelationInfoVoList.forEach(h -> {
            List<CaseStageDocumentDetailInfoVo> caseStageDocumentDetailInfoVos = new ArrayList<>();
            caseStageDocumentDetailInfoVoList.forEach(g -> {
                if (h.getCaseStageCode().equals(g.getCaseStageCode())) {
                    caseStageDocumentDetailInfoVos.add(g);
                }
            });
            List<CaseStageLinkRelateDocumentVo> data  = new ArrayList<>();
            relatedDocList.forEach(i -> {
                if (h.getCaseStageCode().equals(i.getCaseStageCode())) {
                    data.add(i);
                }
            });
            /*List<CaseDocumentCatalogChainOfflineDetailVo> offlineDetailVos = new ArrayList<>();
            documentOfflineDetailVoList.forEach(i->{
                if(h.getCaseStageCode().equals(i.getCaseStageCode())){
                    offlineDetailVos.add(i);
                }
            });*/
            h.setCaseStageDocumentDetailVoList(caseStageDocumentDetailInfoVos);
            h.setRelatedDocList(data);
            //h.setDocumentOfflineDetailVoList(offlineDetailVos);
        });

        for (int i = 0; i < caseStageDocumentRelationInfoVoList.size(); i++) {
            if (caseMainInfo.getCaseCurrentStageCode().equals(caseStageDocumentRelationInfoVoList.get(i).getCaseStageCode())) {
                if (i == caseStageDocumentRelationInfoVoList.size() - 1) {
                    caseStageDocumentRelationInfoVoList.get(i).setStageStatus("1");
                } else {
                    caseStageDocumentRelationInfoVoList.get(i).setStageStatus("2");
                }
            } else {
                if (caseStageDocumentRelationInfoVoList.get(i).getCaseStageDocumentDetailVoList().size() <= 0) {
                    caseStageDocumentRelationInfoVoList.get(i).setStageStatus("3");
                } else {
                    caseStageDocumentRelationInfoVoList.get(i).setStageStatus("1");
                }
            }
        }




        //caseSourceDocumentCatalogChainInfoVos.addAll(caseDocumentCatalogChainInfoVos);
        return caseStageDocumentRelationInfoVoList;


        //1、组装预立案阶段 如果为案源案件 需展示案源相关文书
        /*if (ApiVisitDataSourceEnum.PUNISH_AY.getCode().equals(caseMainInfo.getDataSource())) {
            CaseDocumentCatalogChainInfoVo caseDocumentCatalogChainInfoVo=new CaseDocumentCatalogChainInfoVo();
            caseDocumentCatalogChainInfoVo.setStageName(Constant.CASE_SOURCE_STAGE_YLA);
            caseDocumentCatalogChainInfoVo.setStageCode(Constant.CASE_SOURCE_STAGE_CODE);
            caseDocumentCatalogChainInfoVo.setStageStatus(Constant.STRING_1);
            //获取预调查当事人信息
            Example partyExample=new Example(CaseSourcePartyInfo.class);
            partyExample.createCriteria().andEqualTo("caseSourceId",caseMainInfo.getId()).andEqualTo("status",Constant.STRING_1);
            List<CaseSourcePartyInfo> caseSourcePartyInfos = caseSourcePartyInfoMapper.selectByExample(partyExample);


            //文书列表
            List<CaseDocumentCatalogChainDetailVo> caseDocumentCatalogChainDetailVos = new ArrayList<>();
            CaseSourceLinkRelateDocumentQueryDto query = new CaseSourceLinkRelateDocumentQueryDto();
            query.setCaseSourceId(caseMainInfo.getId());
            query.setDocumentRecordStatus(Constant.STRING_1);
            List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList = caseSourceDocumentRecordService.getCaseStageLinkRelateDocumentInfo(query);

            for (CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo : caseStageLinkRelateDocumentList) {
                caseStageLinkRelateDocumentVo.setIsOnlyDetail(Constant.STRING_1);
                //多当事人
                if(caseSourcePartyInfos.size() > 1){
                    String partyId = caseStageLinkRelateDocumentVo.getPartyId();
                    if (!ObjectUtils.isEmpty(partyId)) {
                        String[] partyIdArr = partyId.split(",");
                        if(partyIdArr.length == 1){
                            CaseSourcePartyInfo caseSourcePartyInfo = caseSourcePartyInfoMapper.selectByPrimaryKey(partyId);
                            if(null != caseSourcePartyInfo){
                                String documentKindName = caseStageLinkRelateDocumentVo.getDocumentKindName() + "(" + caseSourcePartyInfo.getPartyName() + ")";
                                caseStageLinkRelateDocumentVo.setDocumentKindName(documentKindName);
                            }
                        }
                    }
                }
                CaseDocumentCatalogChainDetailVo caseDocumentCatalogChainDetailVo = new CaseDocumentCatalogChainDetailVo();
                BeanUtils.copyProperties(caseStageLinkRelateDocumentVo, caseDocumentCatalogChainDetailVo);
                //关联附件
                CaseAttachmentInfoQueryDto attachmentInfoQueryDto = new CaseAttachmentInfoQueryDto();
                attachmentInfoQueryDto.setCaseId(caseId);
                attachmentInfoQueryDto.setDocumentCatalogCode(caseStageLinkRelateDocumentVo.getDocumentCatalogCode());
                attachmentInfoQueryDto.setPartyId(caseStageLinkRelateDocumentVo.getPartyId());
                List<CaseAttachmentInfoVo> caseAttachmentList = caseAppendixRecordService.getCaseAttachmentList(attachmentInfoQueryDto);
                List<DocumentRelateAttachmentVo> documentRelateAttachmentList = new ArrayList<>();
                caseAttachmentList.forEach(a -> {
                    DocumentRelateAttachmentVo vo = new DocumentRelateAttachmentVo();
                    BeanUtils.copyProperties(a, vo);
                    vo.setAttachmentId(a.getId());
                    vo.setAttachmentTitle(a.getAppendixName());
                    vo.setAttachmentUrl(a.getAppendixUrl());
                    vo.setAttachmentType(a.getAppendixType());
                    documentRelateAttachmentList.add(vo);
                });
                caseDocumentCatalogChainDetailVo.setDocumentRelateAttachmentList(documentRelateAttachmentList);

                caseDocumentCatalogChainDetailVos.add(caseDocumentCatalogChainDetailVo);
            }

            //案源附件查询
            List<CaseDocumentCatalogChainOfflineDetailVo> caseDocumentCatalogChainOfflineDetailVos=new ArrayList<>();
            Example materialExample=new Example(CaseSourceMaterialRecord.class);
            materialExample.createCriteria().andEqualTo("caseSourceId",caseId).andEqualTo("isDelete",Constant.STRING_0);
            List<CaseSourceMaterialRecord> caseSourceMaterialRecordList=caseSourceMaterialRecordMapper.selectByExample(materialExample);
            caseSourceMaterialRecordList.forEach(caseSourceMaterialRecord -> {
                CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo=new CaseStageLinkRelateDocumentVo();
                caseStageLinkRelateDocumentVo.setDocumentUrl(caseSourceMaterialRecord.getMaterialUrl());
                caseStageLinkRelateDocumentVo.setDocumentId(caseSourceMaterialRecord.getId());
                caseStageLinkRelateDocumentVo.setDocumentCreateTime(caseSourceMaterialRecord.getUploadTime());
                caseStageLinkRelateDocumentVo.setCreateUserName(caseSourceMaterialRecord.getUploadUserName());
                caseStageLinkRelateDocumentVo.setDocumentCatalogName(caseSourceMaterialRecord.getMaterialName());
                caseStageLinkRelateDocumentVo.setIsOnlyDetail(Constant.STRING_1);
                if (!ObjectUtils.isEmpty(caseSourceMaterialRecord.getEvidenceUid())) {
                    //证据文件
                    caseStageLinkRelateDocumentVo.setIsEvidenceDoc(YesOrNoEnum.YES.getCode());
                }
                CaseDocumentCatalogChainOfflineDetailVo caseDocumentCatalogChainOfflineDetailVo=new CaseDocumentCatalogChainOfflineDetailVo();
                BeanUtils.copyProperties(caseStageLinkRelateDocumentVo,caseDocumentCatalogChainOfflineDetailVo);
                caseDocumentCatalogChainOfflineDetailVos.add(caseDocumentCatalogChainOfflineDetailVo);
            });
            Collections.sort(caseStageLinkRelateDocumentList, (o1, o2) -> o1.getDocumentCreateTime().compareTo(o2.getDocumentCreateTime()));
            caseDocumentCatalogChainInfoVo.setCaseDocumentCatalogChainDetailVoList(caseDocumentCatalogChainDetailVos);

            caseDocumentCatalogChainInfoVo.setDocumentOfflineDetailVoList(caseDocumentCatalogChainOfflineDetailVos);
            caseSourceDocumentCatalogChainInfoVos.add(caseDocumentCatalogChainInfoVo);
        }*/


        //线下文书
        /*List<CaseDocumentCatalogChainOfflineDetailVo> documentOfflineDetailVoList = caseOfflineDocumentRecordService.doGetCaseDocumentCatalogChainOfflineDetailVo(caseId);
        String territoryCode=caseMainInfo.getCaseTerritoryCode();
        if(TerritoryCodeEnum.ZRZY.getCode().equals(territoryCode)){
            //查询附件
            Example example=new Example(CaseAppendixRecord.class);
            example.createCriteria().andEqualTo("caseId",caseId).andEqualTo("appendixTypeId", AttachmentTypeEnum.ATTACHTYPE74.getCode()).andEqualTo("appendixStatus",Constant.STRING_1).andEqualTo("isDelete",Constant.STRING_0);
            List<CaseAppendixRecord> caseAppendixRecords=caseAppendixRecordMapper.selectByExample(example);
            if(!ObjectUtils.isEmpty(caseAppendixRecords)){
                for (CaseAppendixRecord caseAppendixRecord:caseAppendixRecords) {
                    CaseDocumentCatalogChainOfflineDetailVo vo=new CaseDocumentCatalogChainOfflineDetailVo();
                    vo.setCaseStageCode(caseAppendixRecord.getCaseStageCode());
                    vo.setCaseStageName(caseAppendixRecord.getCaseStageName());
                    vo.setDocumentTittle(caseAppendixRecord.getAppendixName());
                    vo.setDocumentUrl(caseAppendixRecord.getAppendixUrl());
                    documentOfflineDetailVoList.add(vo);
                }
            }

        }*/

    }

    /**
     * 速结程序立案审批表操作按钮特殊处理
     *
     * @param caseStageDocumentDetailInfoVo
     * @param caseId
     */
    private void dealLASPBDocumentOperateInfo(CaseStageDocumentDetailInfoVo caseStageDocumentDetailInfoVo, String caseId) {
        //查询速结告知书是否签字确认
        List<CaseDocumentRecord> caseDocumentRecordOfSJCXGZS = caseDocumentRecordService.getCaseDocumentRecordOfSJCXGZS(caseId);
        if (ObjectUtil.isEmpty(caseDocumentRecordOfSJCXGZS)) return;
        //已确认则不允许修改
        List<CaseStageDocumentOperateVo> caseStageDocumentOperateVoList = caseStageDocumentDetailInfoVo.getCaseStageDocumentOperateVoList();
        if (ObjectUtil.isEmpty(caseStageDocumentOperateVoList)) return;
        //操作
        List<CaseStageDocumentOperateVo> newCaseStageDocumentOperateVoList = new ArrayList<>();
        caseStageDocumentOperateVoList.forEach(e -> {
            if (!"modify".equals(e.getOperateFrontSymble())) {
                newCaseStageDocumentOperateVoList.add(e);
            }
        });
        caseStageDocumentDetailInfoVo.setCaseStageDocumentOperateVoList(newCaseStageDocumentOperateVoList);
    }

    /**
     * 【V1.10.0】描述：初始化文书的操作相关信息（状态、操作）
     *
     * @param caseStageDocumentDetailInfoVo
     * @return
     * @author tianrunjia
     * @date 2022-12-11
     */
    private CaseStageDocumentDetailInfoVo initDocumentOperateInfo(CaseStageDocumentDetailInfoVo caseStageDocumentDetailInfoVo, CaseDocumentRecordInfo stageDocumentRecordInfo, Boolean isMatchDocument) {

        //操作
        List<CaseStageDocumentOperateVo> caseStageDocumentOperateVoList = new ArrayList<>();


        //状态 草稿优先级最高
        if (DocumentRecordStatusEnum.DRAFT.getCode().equals(stageDocumentRecordInfo.getDocumentRecordStatus())) {
            caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusType("DOCUMENT-RECORD-STATUS");
            caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusCode(stageDocumentRecordInfo.getDocumentRecordStatus());
            caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusName(DocumentRecordStatusEnum.getValueByCode(stageDocumentRecordInfo.getDocumentRecordStatus()));
            if (!isMatchDocument) {
                CaseStageDocumentOperateVo operateVo1 = new CaseStageDocumentOperateVo();
                operateVo1.setOperateName("修改");
                operateVo1.setOperateFrontSymble("modify");
                caseStageDocumentOperateVoList.add(operateVo1);

                CaseStageDocumentOperateVo operateVo2 = new CaseStageDocumentOperateVo();
                operateVo2.setOperateName("删除");
                operateVo2.setOperateFrontSymble("delete");
                caseStageDocumentOperateVoList.add(operateVo2);
            }
        } else {
            //审批 送达
            boolean ifSentStatus = false;
            boolean ifSignStatus = false;
            //审批
            if (StringUtils.isNotBlank(stageDocumentRecordInfo.getDocumentApprovalStatus())) {
                CaseStageDocumentOperateVo operateVo1 = new CaseStageDocumentOperateVo();
                CaseStageDocumentOperateVo operateVo2 = new CaseStageDocumentOperateVo();
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusType("DOCUMENT-APPROVAL-STATUS");
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusCode(stageDocumentRecordInfo.getDocumentApprovalStatus());
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusName(DocumentStatusEnum.getValueByCode(stageDocumentRecordInfo.getDocumentApprovalStatus()));
                if (DocumentStatusEnum.WAIT_TO_SUBMIT.getCode().equals(stageDocumentRecordInfo.getDocumentApprovalStatus())) {
                    if (!isMatchDocument) {
                        operateVo1.setOperateName("提交审批");
                        operateVo1.setOperateFrontSymble("approval");
                        caseStageDocumentOperateVoList.add(operateVo1);
                        operateVo2.setOperateName("修改");
                        operateVo2.setOperateFrontSymble("modify");
                        caseStageDocumentOperateVoList.add(operateVo2);
                    }

                } else if (DocumentStatusEnum.CHECKING.getCode().equals(stageDocumentRecordInfo.getDocumentApprovalStatus())) {
                    //wu
                } else if (DocumentStatusEnum.CHECK_BACK.getCode().equals(stageDocumentRecordInfo.getDocumentApprovalStatus())) {
                    if (!isMatchDocument) {
                        operateVo1.setOperateName("提交审批");
                        operateVo1.setOperateFrontSymble("approval");
                        caseStageDocumentOperateVoList.add(operateVo1);
                        operateVo2.setOperateName("修改");
                        operateVo2.setOperateFrontSymble("modify");
                        caseStageDocumentOperateVoList.add(operateVo2);
                    }

                } else if (DocumentStatusEnum.CHECK_END.getCode().equals(stageDocumentRecordInfo.getDocumentApprovalStatus())) {

                    ifSentStatus = true;
                    ifSignStatus = true;
                }
            } else {
                ifSentStatus = true;
                ifSignStatus = true;
            }

            //送达
            if (ifSentStatus && StringUtils.isNotBlank(stageDocumentRecordInfo.getDocumentSentStatus())) {
                CaseStageDocumentOperateVo operateVo2 = new CaseStageDocumentOperateVo();
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusType("DOCUMENT-SENT-STATUS");
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusCode(stageDocumentRecordInfo.getDocumentSentStatus());
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusName(DocumentStatusEnum.getValueByCode(stageDocumentRecordInfo.getDocumentSentStatus()));
                if (DocumentStatusEnum.WAIT_TO_SEND.getCode().equals(stageDocumentRecordInfo.getDocumentSentStatus())) {
                    operateVo2.setOperateName("送达");
                    operateVo2.setOperateFrontSymble("send");
                    caseStageDocumentOperateVoList.add(operateVo2);
                } else if (DocumentStatusEnum.SENT.getCode().equals(stageDocumentRecordInfo.getDocumentSentStatus())) {
                    operateVo2.setOperateName("重新送达");
                    operateVo2.setOperateFrontSymble("send");
                    caseStageDocumentOperateVoList.add(operateVo2);
                }
            }

            //签字
            if (ifSignStatus && StringUtils.isNotBlank(stageDocumentRecordInfo.getDocumentSignstampedStatus())) {
                CaseStageDocumentOperateVo operateVo3 = new CaseStageDocumentOperateVo();
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusType("DOCUMENT-SIGNSTAMPED-STATUS");
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusCode(stageDocumentRecordInfo.getDocumentSignstampedStatus());
                caseStageDocumentDetailInfoVo.setDocumentCurrentBusiStatusName(DocumentStatusEnum.getValueByCode(stageDocumentRecordInfo.getDocumentSignstampedStatus()));
                if (DocumentStatusEnum.WAIT_TO_CONFIRM.getCode().equals(stageDocumentRecordInfo.getDocumentSignstampedStatus())) {
                    operateVo3.setOperateName("签字确认");
                    operateVo3.setOperateFrontSymble("sign");
                    caseStageDocumentOperateVoList.add(operateVo3);
                } else if (DocumentStatusEnum.CONFIRM_END.getCode().equals(stageDocumentRecordInfo.getDocumentSignstampedStatus())) {
                    //无
                }
            }
            CaseStageDocumentOperateVo operateVo4 = new CaseStageDocumentOperateVo();
            //详情
            operateVo4.setOperateName("详情");
            operateVo4.setOperateFrontSymble("detail");
            caseStageDocumentOperateVoList.add(operateVo4);
        }

        //增加处罚决定书是否展示公示详情处理
        /*if (Constant.STRING_KIND_CODE_CFJDS.equals(stageDocumentRecordInfo.getDocumentKindCode())) {
            CaseStageDocumentOperateVo operateVo5 = new CaseStageDocumentOperateVo();
            //默认展示公示详情按钮
            operateVo5.setOperateName("展示公示");
            operateVo5.setOperateFrontSymble("");
            caseStageDocumentOperateVoList.add(operateVo5);
        }*/

        caseStageDocumentDetailInfoVo.setCaseStageDocumentOperateVoList(caseStageDocumentOperateVoList);
        return caseStageDocumentDetailInfoVo;
    }

/*    public static void main(String[] args) {
        List<CarryMaterial> carryMaterialList = new ArrayList<>();
        carryMaterialList.add(new CarryMaterial("2", "2022年09月"));
        carryMaterialList.add(new CarryMaterial("4", "2022年10月至2022年11月"));
        //carryMaterialList.add(new CarryMaterial("5","2022年09月至2022年10月"));
        //carryMaterialList.add(new CarryMaterial("6","2022年09月至2022年10月"));
        Boolean aBoolean = carryMaterial(carryMaterialList);
        System.out.println(aBoolean);
    }*/

    /**
     * 【V1.4.1】描述：返回案件主流程当前环节的操作按钮-详情页底部，包括流程操作、下一步、更多操作
     *
     * @param caseId 入参
     * @return CaseCurrentLinkOperateVo
     * @author tianrunjia
     * @date 2022/8/25
     **/
    @Override
    public CaseCurrentLinkOperateVo doGetCaseCurrentLinkOperate(String caseId) {
        CaseMainInfoVo caseMainInfoVo = caseMainInfoService.getCaseMainInfo(caseId);
        CaseCurrentLinkOperateVo caseCurrentLinkOperateVo = new CaseCurrentLinkOperateVo();
        if (caseMainInfoService.validateCaseIsInNotDealStatus(caseMainInfoVo, null)) {
            return caseCurrentLinkOperateVo;
        }
        //暂存状态的案件不应该返回操作数据
        if (CaseStatusEnum.TEMP.getCode().equals(caseMainInfoVo.getCaseStatus())) {
            return caseCurrentLinkOperateVo;
        }
        List<ConfigWorkFlowOperateDetailInfo> configWorkFlowOperateDetailInfoList = configWorkFlowOperateDetailInfoService.getConfigWorkFlowOperateDetailInfoListByLinkCode(caseMainInfoVo.getCaseFlowCode(), caseMainInfoVo.getCaseCurrentLinkCode());
        List<CaseCurrentLinkMoreOperateVo> caseCurrentLinkMoreOperateVoList = new ArrayList<>();

        UserDTO userDTO = UserUtil.getUserInfo();
        List<String> roleIdList = userRoleFeignApi.getRoleIdList(userDTO.getUserId().toString(), userDTO.getOrgCode());

        configWorkFlowOperateDetailInfoList.forEach(e -> {
            //1、主流程 且 操作对象为案件
            if ("1".equals(e.getOperateLinkType()) && "1".equals(e.getOperateObjectType())) {
                if ("1".equals(e.getOperateType())) {
                    //多当事人 且 分别处罚的情况下，不展示下一环节
                    if ("3".equals(caseMainInfoVo.getCasePartiesReasonType()) && "2".equals(caseMainInfoVo.getHandleType())) {
                        caseCurrentLinkOperateVo.setCaseNextLinkOperateVo(null);
                    } else {
                        //1、送达 和 签字、审批环节，不展示下一环节 TODO 未来做更合理优化
                        if (!"CLOSE-TRIGGER-APPROVAL-PASS".equals(e.getRollSignal()) && !"CLOSE-TRIGGER-SENT".equals(e.getRollSignal()) && !"CLOSE-TRIGGER-SIGNSTAMPED".equals(e.getRollSignal())) {
                            //如果有下一环节多个操作，则不展示下一环节 TODO 以后根据业务需求再做调整
                            if (!ObjectUtils.isEmpty(caseCurrentLinkOperateVo.getCaseNextLinkOperateVo())) {
                                caseCurrentLinkOperateVo.setCaseNextLinkOperateVo(null);
                            } else {
                                boolean roleRight = false;
                                if (roleIdList.contains(e.getOperateAuthRole())) {
                                    roleRight = true;
                                }
                                if (roleRight) {
                                    CaseNextLinkOperateVo caseNextLinkOperateVo = new CaseNextLinkOperateVo();
                                    caseNextLinkOperateVo.setCatalogCode(e.getDocumentCatalogCode());
                                    caseNextLinkOperateVo.setFrontSymble(e.getFrontSymble());
                                    caseNextLinkOperateVo.setNextLinkOperateButtonName("下一环节");
                                    //简案快办下一环节按钮名称特殊处理
                                    if (CaseTypeEnum.FAST_PROCEDURE.getCode().equals(caseMainInfoVo.getCaseType())) {
                                        ConfigBusiParamDocumentInfo detailByDocumentCatalogCode = configBusiParamDocumentInfoService.getDetailByDocumentCatalogCode(e.getDocumentCatalogCode());
                                        if (DocumentKindEnum.DOC_KIND_DK2FQCSSBSM.getCode().equals(detailByDocumentCatalogCode.getDocumentKindCode())) {
                                            caseNextLinkOperateVo.setNextLinkOperateButtonName(e.getWorkOperateName());
                                        }
                                    }
                                    caseCurrentLinkOperateVo.setCaseNextLinkOperateVo(caseNextLinkOperateVo);
                                }
                            }
                        }
                    }
                } else if ("2".equals(e.getOperateType())) {
                    CaseCurrentLinkMoreOperateVo moreOperateVo = new CaseCurrentLinkMoreOperateVo();
                    moreOperateVo.setOperateCode(e.getWorkOperateCode());
                    moreOperateVo.setOperateName(e.getWorkOperateName());
                    moreOperateVo.setCatalogCode(e.getDocumentCatalogCode());
                    moreOperateVo.setFrontSymble(e.getFrontSymble());
                    caseCurrentLinkMoreOperateVoList.add(moreOperateVo);
                }
            }
        });
        caseCurrentLinkOperateVo.setCurrentLinkMoreOperateVoList(caseCurrentLinkMoreOperateVoList);
        return caseCurrentLinkOperateVo;
    }

    /**
     * 根据案件id获取案件详情数据
     *
     * @param caseId
     * @return {@link CaseMainDetailInfo}
     * @author wangfawei
     * @date 2022/12/6
     */
    @Override
    public CaseMainDetailInfo getCaseMainDetailInfoByCaseId(String caseId) {
        Example example = new Example(CaseMainDetailInfo.class);
        example.createCriteria().andEqualTo("caseId", caseId);
        example.createCriteria().andLike("punishKinds", "罚款");
        List<CaseMainDetailInfo> caseMainDetailInfos = caseMainDetailInfoMapper.selectByExample(example);
        if (null != caseMainDetailInfos && caseMainDetailInfos.size() > 0) {
            CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfos.get(0);
            return caseMainDetailInfo;
        } else {
            throw new BusinessException("未获取到案件详情信息-caseId:" + caseId);
        }
    }

    /**
     * 转普通程序宽表数据初始化
     *
     * @param caseId
     */
    public void dealCaseMainDetailInfoOfChangeWorkFlow(String caseId) {
        //查询案件详情
        CaseMainDetailInfo detailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        if (ObjectUtil.isNotEmpty(detailInfo)) {
            CaseMainDetailInfo newDetailInfo = new CaseMainDetailInfo();
            newDetailInfo.setId(detailInfo.getId());
            newDetailInfo.setCaseId(caseId);
            newDetailInfo.setCaseSourceId(detailInfo.getCaseSourceId());
            newDetailInfo.setCaseHappenTime(detailInfo.getCaseHappenTime());
            newDetailInfo.setCaseHappenAddressAreaCode(detailInfo.getCaseHappenAddressAreaCode());
            newDetailInfo.setCaseHappenAddressDetail(detailInfo.getCaseHappenAddressDetail());
            newDetailInfo.setCaseRegisterTime(detailInfo.getCaseRegisterTime());
            newDetailInfo.setCaseName(detailInfo.getCaseName());
            newDetailInfo.setCaseConciseCondition(detailInfo.getCaseConciseCondition());
            newDetailInfo.setCreateTime(detailInfo.getCreateTime());
            newDetailInfo.setUpdateTime(detailInfo.getUpdateTime());
            newDetailInfo.setCaseReason(detailInfo.getCaseReason());
            caseMainDetailInfoMapper.updateByPrimaryKey(newDetailInfo);
            //删除补充表信息
            Example example = new Example(CaseMainDetailAuxiliaryInfo.class);
            example.createCriteria().andEqualTo("caseId", caseId);
            caseMainDetailAuxiliaryInfoMapper.deleteByExample(example);
        }
    }
}
